::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::
This is a brief demo to show people new to Liberty Basic how they can use LB to do some neat things with very little code and no DLL calls. Although the demo just draws straight lines, it does show how the LB debugger can be very useful in debugging code containing lots of event traps. It uses the new subroutine event handlers (there are lots of examples around now of this feature). It gives some insight as to how Windows holds the focus until a left mouse button press is received. It also shows how the LB XOR drawing rule allows a kind of pseudo-animation effect to be achieved very simply. Finally it shows how a graphicbox is much bigger than you might think.
This article follows Einstein's First Law. Make it as simple as possible but no simpler.
Here's the code with the added debug statements turned on:
' program to to use subroutine mouse traps to
' draw a line between two points in a rectangular area
'___________________________________________________________
global debug
debug = (1=1) ' replace 1=0 with 1=1 to turn on debug
'NOMAINWIN ' and comment out this line
'___________________________________________________________
global StartX, StartY, EndX, EndY
UpperLeftX = 350
WindowWidth = 550
WindowHeight = 300
graphicbox #main.box, 50,50,200,200
graphicbox #main.box2, 300,50,200,200
open "Line Drawing" for window as #main
#main "trapclose [quit]"
#main.box "when leftButtonDown startLine"
#main.box "when leftButtonUp endLine"
#main.box "when leftButtonMove redraftLine"
#main.box2 "when leftButtonDown startLine"
#main.box2 "when leftButtonUp endLine"
#main.box2 "when leftButtonMove redraftLine"
#main.box, "rule "; _R2_NOTXORPEN ' drawing rule xor mode for easy erasing
#main.box2, "rule "; _R2_NOTXORPEN ' drawing rule xor mode for easy erasing
wait
[quit]
close #main: end
sub startLine handle$, x, y
if debug then print "startLine", handle$, x, y
StartX = x
StartY = y
EndX = x
EndY = y
call drawLine handle$ ' the line - at this stage just a point
end sub
sub endLine handle$, x, y
if debug then print "endLine", handle$, x, y
' line drawing complete make it stick
#handle$ "flush"
end sub
sub redraftLine handle$, x, y
if debug then print "redraftLine", handle$, x, y
call drawLine handle$ ' to erase current line before updating end point
EndX = x : EndY = y ' to update end point
call drawLine handle$ ' to redraw the line to new end point
end sub
sub drawLine handle$
#handle$, "down" ' pen down
#handle$, "line ";StartX;" ";StartY;" ";EndX;" ";EndY ' draw line
#handle$ "set ";EndX;" ";EndY ' draw end point
#handle$ "up" ' pen up
end sub
::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::